package com.forum.config.WebSocket;

import java.util.HashMap;
import java.util.Map;

public class UserContextManager {
    private static final Map<Integer, ConversationContext> userContexts = new HashMap<>();

    public static void addOrUpdateContext(int userId, String question, String answer) {
        ConversationContext context = userContexts.getOrDefault(userId, new ConversationContext());
        context.addMessage(question, answer);
        userContexts.put(userId, context);
    }

    public static ConversationContext getContext(int userId) {
        return userContexts.getOrDefault(userId, new ConversationContext());
    }

    public static class ConversationContext {
        private final StringBuilder conversationHistory = new StringBuilder();

        public void addMessage(String question, String answer) {
            conversationHistory.append("User: ").append(question).append("\n");
            conversationHistory.append("AI: ").append(answer).append("\n");
        }

        public String getConversationHistory() {
            return conversationHistory.toString();
        }
    }
}